<?php
use app\models\Menu;
use yii\helpers\Url;

$route = Yii::$app->controller->route;
$controllerId = Yii::$app->controller->id;
$module_id = Yii::$app->controller->module->id;
$allMenus = Menu::getMenu();

?>
<aside class="main-sidebar">

    <!-- sidebar: style can be found in sidebar.less -->
    <section class="sidebar">
        <!-- Sidebar Menu -->
        <ul class="sidebar-menu">
            <?php foreach ($allMenus as $menus): ?>
                <li class="treeview ">
                    <a href="<?=Url::to([$menus['url']])?>">
                        <i class="fa <?=$menus['icon_style'];?>"></i>
                        <span><?=$menus['name'];?></span>
                        <span class="pull-right-container">
                          <i class="fa fa-angle-left pull-right"></i>
                        </span>
                    </a>
                    <ul class="treeview-menu">
                        <?php
                        if (!isset($menus['_child'])) break;
                        foreach ($menus['_child'] as $menu) {
                            $menuArr = explode('/', $menu['url']);
                            ?>
                            <li class="<?=Yii::$app->controller->id == $menuArr[0] ? 'active' : '';?>"><a href="<?=Url::to([$menu['url']]);?>""><i class="fa <?=$menu['icon_style'];?>"></i><?=$menu['name'];?></a></li>
                        <?php } ?>
                    </ul>
                </li>
            <?php endforeach; ?>
        </ul>
        <!-- /.sidebar-menu -->
    </section>
    <!-- /.sidebar -->
</aside>
<?php
$cssStr = <<<EOF
.sidebar-menu li.active>a .fa-angle-left {     
    -webkit-transform: rotate(-90deg);
    -ms-transform: rotate(-90deg);
    -o-transform: rotate(-90deg);
    transform: rotate(-90deg); }
.sidebar-menu>li>a {
    padding-right: 15px;    
}    
EOF;
$this->registerCss($cssStr);
$jsStr = <<<EOF
$('.active').parent().parent().addClass('active');
EOF;
$this->registerJs($jsStr);